<template>
  <component :is="lazyComponent" v-if="lazyComponent" />
</template>

<script setup>
import { defineAsyncComponent, ref } from "vue";
import { useStore } from "@/store/index";

const lazyComponent = ref(null);
const store = useStore();
const loadComponent = async (url) => {
  // 使用 defineAsyncComponent 和 import() 函数懒加载组件
  let LazyComponent = null
  if(store.isPc==2){
    LazyComponent = defineAsyncComponent(() => import('./mobile.vue'));
  }else{
     LazyComponent = defineAsyncComponent(() => import('./pc.vue'));
  }
  lazyComponent.value = LazyComponent;
};
watch(() => store.isPc, (newVal) => {
  loadComponent()
}, {immediate: true})

onMounted(() => {
  const element = document.getElementById("app");
  element.scrollTop = 0;
});
</script>

<style scoped>
/* 你的样式 */
</style>
